package org.mtdownload.app.loader;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
/*
 * Created on 30-Jan-2005
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */

/**
 * the JarClassLoaderConnection 
 * @author sergiu
 */
public class JarClassLoaderConnection extends URLConnection {

   private boolean gotData = false;  // Did we get the data?
   private InputStream data;
   
	public JarClassLoaderConnection(URL url){
		super(url);
	}
	
	/* (non-Javadoc)
	 * @see java.net.URLConnection#connect()
	 */
	public void connect() throws IOException {
		System.out.println(getClass().getClassLoader().getClass());
		JarClassLoader ourLoader=(JarClassLoader)getClass().getClassLoader();
		data=ourLoader.getInputStreamForResource(url.getFile());
		gotData=true;
	}
	
	/* (non-Javadoc)
	 * @see java.net.URLConnection#getInputStream()
	 */
	public InputStream getInputStream() throws IOException {
		if(!gotData){
			connect();
		}
		return data;
	}
}
